@extends('admin.common.base-master')

@section('html-head')
    {{--<link href="{{url('/vendor/tyupload/control/css/zyUpload.css')}}" type="text/css" rel="stylesheet" />--}}
    <link href="{{url('css/jquery.form.css')}}" type="text/css" rel="stylesheet" />
    {{--<script src="{{url('/vendor/My97DatePicker/WdatePicker.js')}}"></script>--}}
    <script src="{{url('/js/lib/jquery.form.js')}}"></script>

    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script type="text/javascript" src="//code.jquery.com/ui/1.9.1/jquery-ui.min.js"></script>

    <style>
        .btn_add_classify{
            background: #31bcd3;margin-left:10px;height: 5px;width: 50px;color: white;text-align: center;padding:5px;border-radius:7px;box-shadow: 3px 2px 9px #888888;
        }
    </style>
    @include('UEditor::head')
@endsection

@section('html-body')
    <!-- content start -->

    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            @if($type == 'comment')
                <a href="{{route('Admin.Home.commentList')}}">评论列表</a>
            @else
                <a href="{{route('Admin.Home.enCommentList')}}">英文-评论列表</a>
            @endif
            <em>></em>
            <a href="#">内容设置</a>
        </div>

        @include('admin.common.human-res-header')

        <div class="gg-step">
            <form  id="advform">
                <input type="hidden" name="id" id="goodsid" value="@if($thisHumanRes && $thisHumanRes->id){{$thisHumanRes->id}} @endif"/>
                <input type="hidden" name="type" id="type" value="{{$type}}"/>
                <div class="gg-list">
                    <label class="tit">姓名</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入姓名" name="realname" id="realname" value="@if($thisHumanRes){{$thisHumanRes->realname}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入2-40个字符（一个汉字等于2个字符）</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">职位</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入职位" name="position" id="position" value="@if($thisHumanRes){{$thisHumanRes->position}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入10-40个字符（一个汉字等于2个字符）</p>
                    </div>
                </div>

                <div class="gg-list" data-id="ggzst2">
                    <label class="tit">头像</label>
                    <div class="demo" style="display: inline-block; padding: 0; margin: 0; *display: inline; *zoom:1;">
                        <input type = "hidden" name = "pic_img" id = "pic_img2" value = "" height="70px" >
                        <div id="showimg">
                        </div>
                        <div class="btn" style="background: #00A2D4">
                            <span id="inputImage">添加图片</span>
                            <input id="img_id" type="hidden" name="thumb_id" value="@if($thisHumanRes){{$thisHumanRes->photo_id}}@endif">
                        </div>
                        <div class="progress">
                            <span class="bar"></span><span class="percent">0%</span >
                        </div>
                        <p class="text" id="uploadthumb">上传banner（图片格式为jpg、png、gif，规格：高限90px 宽限95px）</p>
                        @if($thisHumanRes)<img id="img_show" style="width: 100px;padding-top: 3px;" src="{{$thisHumanRes->photo_url}}" />@endif

                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">内容</label>
                    <textarea name="description" id="aa"></textarea>
                </div>

                <div class="gg-list">
                    <label class="tit">排序</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入排序" name="sort" id="sort" value="@if($thisHumanRes){{$thisHumanRes->sort}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">输入数值，1－100 数值越小越靠前</p>
                    </div>
                </div>


            </form>
            <div class="gg-list" >
                <label class="tit">&nbsp;</label>
                <div class="cont" >
                    <a href="javascript:;" class="next-step" id="btn-set">提交</a>
                </div>
            </div>
        </div>
    </div>

    <!-- content end -->
    <script>
        $(function() {

            <!-- 实例化编辑器 -->
            var ue = UE.getEditor('aa',{
                autoHeightEnabled: true,
                initialFrameHeight:400,
                initialFrameWidth:600,
                toolbars: [
                    ['fullscreen', 'source','undo','redo','|','fontsize','horizontal','|','simpleupload','insertvideo','removeformat'],
                    ['bold', 'italic', 'underline', 'forecolor', 'backcolor','|','indent','|','justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|', 'rowspacingtop', 'rowspacingbottom', 'lineheight','|','insertunorderedlist', 'insertorderedlist','|', 'imagenone','imageleft','imageright','imagecenter','|','link']
                ]
            });

            @if($thisHumanRes)
            ue.ready(function() {
                        ue.setContent('<?php echo $thisHumanRes->content ?>');
                    });
            @endif

            $(document).on('click', '#btn-set', function () {
                var content = "";

                ue.ready(function() {
                    content = ue.getContent();
                });
                var realname       = $('#realname').val();
                var position       = $('#position').val();
                var imgId          = $('#img_id').val();
                var type           = $("#type").val();
                var id             = $('#goodsid').val();
                var sort           = $('#sort').val();


                $.ajax({
                    url: '{{route("Api.Admin.sys.setHumanRes")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        content:content,
                        position:position,
                        realname:realname,
                        img_id:imgId,
                        type:type,
                        id:id,
                        sort:sort

                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose:function(){
                                        if(type == 'comment'){
                                            window.location.href = "{{route('Admin.Home.commentList')}}";
                                        }else{
                                            window.location.href = "{{route('Admin.Home.enCommentList')}}";
                                        }
                                    }
                                }
                            });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });

            //缩略图上传代码
            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight,html4',
                browse_button: 'inputImage',
                url: '{{route("Api.File.upload")}}',

                chunk_size: '20mb',
                filters: {
                    max_file_size: '5mb',
                    mime_types: [
                        {title: "Image files", extensions: "jpg,gif,png"}
                    ],
                    prevent_duplicates: false
                },
                multi_selection: true,
                unique_names: true,

                flash_swf_url: '{{ url('vendor/plupload-2.1.2/Moxie.swf') }}',
                silverlight_xap_url: '{{ url('vendor/plupload-2.1.2/Moxie.xap') }}',

                file_data_name: 'photo',
                headers: {
                    Accept: 'application/json'
                },

                multipart_params: {},

                init: {
                    PostInit: function () {
                    },

                    FilesAdded: function (up, files) {
                        up.start();
                    },

                    BeforeUpload: function (up, file) {
                        up.settings.multipart_params.file_name = file.name;
                    },

                    UploadProgress: function (up, file) {
                        $('#uploadthumb').html('<span style="color:red">上传中...</span>');
                    },

                    Error: function (up, err) {
                        var responseObj = '', responseMessage = '';
                        try {
                            responseObj = $.parseJSON(err.response);
                            responseMessage = responseObj.message;
                        } catch ($e) {

                        }

                        noty({
                            type: 'error',
                            text: err.message + ' ' + responseMessage,
                            timeout: 800
                        });
                    },

                    FileUploaded: function (up, file, info) {
                        var responseObj = '', responseMessage = '';
                        try {
                            responseObj = $.parseJSON(info.response);
                            responseMessage = responseObj.message;
                        } catch ($e) {

                        }
                        if (responseObj.level == "success") {
                            $('#img_id').val(responseObj.data.id);
                            var imgURL = responseObj.data.img_url + "?" + Math.random();
                            $('#img_show').attr("src",imgURL);
                            $('#uploadthumb').html('<span style="color:green">上传成功</span>');
                        } else {
                            noty({type: responseObj.level, text: responseObj.message, timeout: 800});
                            $('#uploadthumb').html('<span style="color: red">上传失败，请重新上传！</span>');
                        }

                    }
                }
            });
            uploader.init();
        });
    </script>

@endsection